package com.example.experiment4

import java.util.*

class Deck {
    private val cards = mutableListOf<Card>()

    init {
        reset()
    }

    fun reset() {
        cards.clear()
        for (i in 1..8) { // 8对牌，共16张
            val card1 = Card()
            val card2 = Card()
            card1.identifier = i
            card2.identifier = i
            cards.add(card1)
            cards.add(card2)
        }
        Collections.shuffle(cards) // 洗牌
    }

    fun size(): Int = cards.size
    fun dealCard(): Card? = if (cards.isEmpty()) null else cards.removeAt(0)
}